package src.com.test.twoDay;

import java.util.ArrayList;
import java.util.List;

public class demo2 {

    public static void main(String[] args) {

        System.out.println(isOk("255"));
        System.out.println(isOk("056"));
    }

    List<String> res = new ArrayList<>();
    StringBuffer path = new StringBuffer();
    int size = 0;

    public List<String> restoreIpAddresses(String s) {


        return res;
    }
    public void tracebacking(String s,int index){

        if(index >= s.length() && path.length() == s.length() + 4){
            res.add(new String(path));
            return;
        }

        for(int i = index;i < s.length();i++){

            String str = s.substring(index,i - index + 1);
            if(isOk(str)){
                path.append(str);
                path.append('.');
                size = str.length() + 1;
            }else {
                continue;
            }
            tracebacking(s,i + 1);
            path.delete(path.length() - 5,path.length());

        }
    }

    public static boolean isOk(String s){

        if(s.length() != 1 && s.charAt(0) == '0'){
            return false;
        }

        int num = Integer.parseInt(s);

        return num >=0 && num <= 255;
    }
}
